package com.mkl.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mkl.system.common.DataGridView;
import com.mkl.system.vo.LoginfoVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mkl.system.mapper.LoginfoMapper;
import com.mkl.system.domain.Loginfo;
import com.mkl.system.service.LoginfoService;

/**
 * @author king
 * @version 1.0
 * @date 2020/3/4 15:23
 */
@Service
public class LoginfoServiceImpl extends ServiceImpl<LoginfoMapper, Loginfo> implements LoginfoService {

    @Autowired
    private LoginfoMapper loginfoMapper;

    @Override
    public DataGridView queryAllLoginfo(LoginfoVo loginfoVo) {
        IPage<Loginfo> loginfoPage = new Page<>(loginfoVo.getPage(), loginfoVo.getLimit());
        QueryWrapper<Loginfo> qw = new QueryWrapper<>();
        //根据条件模糊查询
        qw.like(StringUtils.isNotBlank(loginfoVo.getLoginname()), "loginname", loginfoVo.getLoginname());
        qw.like(StringUtils.isNotBlank(loginfoVo.getLoginip()), "loginip", loginfoVo.getLoginip());
        qw.ge(loginfoVo.getStartTime() != null, "logintime", loginfoVo.getStartTime());
        qw.le(loginfoVo.getEndTime() != null, "logintime", loginfoVo.getEndTime());
        qw.orderByDesc("logintime");
        loginfoMapper.selectPage(loginfoPage, qw);
        return new DataGridView(loginfoPage.getTotal(), loginfoPage.getRecords());
    }
}
